package Solutions

import "sort"
func sortedSquares(nums []int) []int {
    i:=sort.SearchInts(nums,0)
    if i==len(nums)||nums[i]!=0{
        i--
    }
    j:=i+1;
    
    ans:=make([]int,0,len(nums))
    for i>=0&&j<len(nums){
        if __abs(nums[i])<__abs(nums[j]){
            ans=append(ans,nums[i]*nums[i])
            i--
        }else{
            ans=append(ans,nums[j]*nums[j])
            j++
        }
    }
    for i>=0{
        ans=append(ans,nums[i]*nums[i])
        i--
    }
    for j<len(nums){
        ans=append(ans,nums[j]*nums[j])
        j++
    }
    return ans
}
func __abs(a int)int{
    if a>0{
        return a
    }
    return -a
}